<script setup lang="ts">
import { homeNavs, article } from './composable/home-navs'

const { homeArticleParams } = article()
const { homeConsultationNav, homeOrderNav, tabList } = homeNavs()

import KnowledgeList from './components/KnowledgeList.vue'
import FollowDoctor from './components/FollowDoctor.vue'

import { useStore } from './composable/home-navs'

import { useRouter } from 'vue-router'

const router = useRouter()

const { onUseStore } = useStore(router)
</script>

<template>
  <div class="home-page">
    <!-- 头部 -->
    <div class="home-header">
      <div class="con">
        <h1>优医</h1>
        <div class="search">
          <cp-icon name="home-search" /> 搜一搜：疾病/症状/医生/健康知识
        </div>
      </div>
    </div>
    <!-- 导航 -->
    <div class="home-navs">
      <van-row :key="homeConsultationNav.span">
        <van-col
          :span="homeConsultationNav.span"
          v-for="cols in homeConsultationNav.navs"
          :key="cols.icon"
        >
          <a
            href="javaScript:;"
            class="nav"
            :class="homeConsultationNav.class"
            @click="onUseStore(cols.link, cols.type)"
          >
            <cp-icon :name="cols.icon"></cp-icon>
            <p class="title">{{ cols.label.title }}</p>
            <p class="desc" v-if="cols.label.desc">{{ cols.label.desc }}</p>
          </a>
        </van-col>
      </van-row>

      <van-row :key="homeOrderNav.span">
        <van-col
          :span="homeOrderNav.span"
          v-for="cols in homeOrderNav.navs"
          :key="cols.icon"
        >
          <router-link :to="cols.link" class="nav" :class="homeOrderNav.class">
            <cp-icon :name="cols.icon"></cp-icon>
            <p class="title">{{ cols.label.title }}</p>
            <p class="desc" v-if="cols.label.desc">{{ cols.label.desc }}</p>
          </router-link>
        </van-col>
      </van-row>
    </div>
    <!-- 轮播图 -->
    <div class="home-banner">
      <van-swipe indicator-color="#fff">
        <van-swipe-item>
          <img src="@/assets/ad.png" alt="" />
        </van-swipe-item>
        <van-swipe-item>
          <img src="@/assets/ad.png" alt="" />
        </van-swipe-item>
      </van-swipe>
    </div>
    <!--  -->
    <van-tabs shrink sticky v-model:active="homeArticleParams.type">
      <van-tab
        :name="item.type"
        v-for="item in tabList"
        :key="item.type"
        :title="item.label"
      >
        <FollowDoctor v-if="homeArticleParams.type === 'like'" />
        <knowledge-list :type="item.type" />
      </van-tab>
    </van-tabs>
  </div>
</template>

<style scoped lang="scss">
.home-header {
  height: 100px;
  position: relative;
  &::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 90px;
    background: linear-gradient(180deg, rgba(62, 206, 197, 0.85), #26bcc6);
    border-bottom-left-radius: 150px 20px;
    border-bottom-right-radius: 150px 20px;
  }
  .con {
    position: relative;
    padding: 0 15px;
    > h1 {
      font-size: 18px;
      color: #fff;
      font-weight: normal;
      padding: 20px 0;
      line-height: 1;
      padding-left: 5px;
    }
    .search {
      height: 40px;
      border-radius: 20px;
      box-shadow: 0px 15px 22px -7px rgba(224, 236, 250, 0.8);
      background-color: #fff;
      display: flex;
      align-items: center;
      padding: 0 20px;
      color: var(--cp-dark);
      font-size: 13px;
      .cp-icon {
        font-size: 16px;
        margin-right: 5px;
      }
    }
  }
}
.home-navs {
  padding: 10px 15px 0 15px;
  .nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
    .cp-icon {
      font-size: 48px;
    }
    .title {
      font-weight: 500;
      margin-top: 5px;
      color: var(--cp-text1);
    }
    .desc {
      font-size: 11px;
      color: var(--cp-tag);
      margin-top: 2px;
    }
    &.min {
      .cp-icon {
        font-size: 31px;
      }
      .title {
        font-size: 13px;
        color: var(--cp-text2);
        font-weight: normal;
      }
    }
  }
}
.home-banner {
  padding: 10px 15px;
  height: 100px;
  img {
    width: 100%;
    height: 100%;
  }
}
</style>
